<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('order_code', 100)->unique()->comment('订单号');
            $table->decimal('payment', 19,5)->comment('支付金额');
            $table->decimal('discount', 19,5)->comment('优惠');
            $table->decimal('freight', 19,5)->comment('运费');
            $table->decimal('tax', 19,5)->comment('税费');
            $table->decimal('goods_value', 19,5)->comment('货值');
            $table->char('buyer_id_number', 18)->comment('订购人身份证');
            $table->string('buyer_name', 20)->comment('订购人姓名');
            $table->string('buyer_phone', 20)->comment('订购人电话');
            $table->string('receiving_name', 20)->comment('收件人姓名');
            $table->string('receiving_phone', 20)->comment('收件人手机号');
            $table->string('receiving_address', 150)->comment('地址');
            $table->string('receiving_province', 20)->comment('省');
            $table->string('receiving_city', 20)->comment('市');
            $table->string('receiving_district', 20)->comment('区 ');
            $table->tinyInteger('status')->default(0)->comment('状态： 0 对接中  1 对接失败 2 待发货 3 已发货');
            $table->string('remark', 100)->nullable()->default('对接中...')->comment('说明');
            $table->timestamps();

        });

        Schema::create('order_products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('order_id');
            $table->integer('quantity')->comment('数量');
            $table->string('sku', 100)->comment('sku');
            $table->decimal('price')->comment('价格');
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
        Schema::dropIfExists('order_products');
    }
}
